home *** CD-ROM | disk | FTP | other *** search
- /*
- * Stream filter to change 8 bit bytes into printable ASCII which will
- * survive most networks -- especially the RSCS community which seems
- * to gobble up all sorts of the "ordinary" characters.
- * Encoding is into a 64 character set "[A-Z][a-z][0-9]+-". This means
- * that using 4 characters we can safely represent 3 bytes. Some overhead
- * but I can take it.
- */
-
- #include <stdio.h>
- #include "coder.h"
- #define MAXPERLINE 79 /* max chars/line */
- char *myname;
-
- main(argc,argv)
- char **argv;
- {
- register FILE *fin = stdin, *fout = stdout; /* faster in a register */
- register int c, bcount, ccount = MAXPERLINE-1;
- register long word;
-
- myname = argv[0];
- if (argc == 2 && (fin = fopen(argv[1], "r")) == NULL) {
- fprintf(stderr, "%s: ", myname);
- perror(argv[1]);
- exit(1);
- }
- else if (argc > 2) {
- fprintf(stderr, "usage: %s [file]\n", myname);
- exit(1);
- }
-
- #define charout(c) \
- putc(c, fout); \
- if (--ccount == 0) { \
- putc('\n', fout); \
- ccount = MAXPERLINE-1; \
- }
-
- fputs(header, fout);
- word = 0;
- bcount = 3;
- while ((c = getc(fin)) != EOF) {
- word <<= 8;
- word |= c;
- if (--bcount == 0) {
- charout(ENCODE((word >> 18) & 077));
- charout(ENCODE((word >> 12) & 077));
- charout(ENCODE((word >> 6) & 077));
- charout(ENCODE((word ) & 077));
- word = 0;
- bcount = 3;
- }
- }
- /*
- * A trailing / marks end of data.
- * The last partial encoded word follows in hex,
- * preceded by the byte count.
- */
- if (ccount != MAXPERLINE-1) /* avoid empty lines */
- putc('\n', fout);
- fprintf(fout, "/%d%x\n", 3-bcount, word);
- exit(0);
- }
-